package com.wfm.leetcode.editor.cn;

import java.util.HashMap;
import java.util.Map;

/**
 * 就是简单用map存key val为出现次数
 * 遍历map，找到val=1 的key
 */
public class POne37只出现一次的数字II{
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int singleNumber(int[] nums) {
        Map<Integer, Integer> freq = new HashMap<Integer, Integer>();
        for (int num : nums) {
            freq.put(num, freq.getOrDefault(num, 0) + 1);
        }
        int ans = 0;
        for (Map.Entry<Integer, Integer> entry : freq.entrySet()) {
            int num = entry.getKey(), occ = entry.getValue();
            if (occ == 1) {
                ans = num;
                break;
            }
        }
        return ans;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) { 
        Solution solution = new POne37只出现一次的数字II().new Solution();
    }
}